/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AuthPenSign.GUI;

import AuthPenSign.Signature.Point;
import AuthPenSign.Signature.Signature;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;

/**
 *
 * @author V-ray
 */
public class OutFrame extends javax.swing.JFrame {

	/**
	 * Creates new form OutFrame
	 */
	public OutFrame() {
		initComponents();

		this.g2d = (Graphics2D) this.jPanel1.getGraphics();
		this.g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
		this.g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
		this.g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 780, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 428, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
	private Graphics2D g2d;

	public void DrawSignature(Signature sign) {
		this.Draw(sign.getPoints(), Color.BLACK);
	}

	public void DrawSignature(Signature sign_1, Signature sign_2) {
		this.Draw(sign_1.getPoints(), Color.RED);
		this.Draw(sign_2.getPoints(), Color.BLACK);
	}

	private void Draw(Point[] points, Color color) {

		double koeff = 1;
		int offset = 250;

		Point2D.Double prevLoc = new Point2D.Double();
		Point2D.Double curLoc = new Point2D.Double();
		prevLoc.x = points[0].x * koeff + offset;
		prevLoc.y = points[0].y * koeff * (-1) + offset;

		for (Point p : points) {
			//float brushSize = (float) ((points[i].pressure + 0.5) * 10);
			this.g2d.setColor(color);
			this.g2d.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));

			curLoc.x = p.x * koeff + offset;
			curLoc.y = p.y * koeff * (-1) + offset;

			this.g2d.draw(new Line2D.Double(prevLoc, curLoc));

			prevLoc.x = p.x * koeff + offset;
			prevLoc.y = p.y * koeff * (-1) + offset;
		}
	}
}
